
class APIException(type):
    """
    API exception factory.
    Autogenerate Exception with given name.
    """
    def __new__(mcs, name,bases, message):
        mydict = dict( msg=message, 
        __str__=lambda self: repr(self.msg),
        )
        newException=type.__new__(mcs, name, (Exception,), mydict)
        return newException


#definition of exceptions
errors = { 'KeyDoesNotExists': { 'message': "There is no such child for current DataNode.", 'code': 'API.DataNode.Error.KeyDoesNotExists' },
}


# Exception classes generation
modul = globals()
exceptionActions = dict(__str__=lambda self: repr(self.message))
for err in errors:
    modul[ err] = type(err, (Exception,), dict(errors[err].items()+exceptionActions.items()))
